package com.vehicle.service.ServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vehicle.mapper.CarMapper;
import com.vehicle.mapper.CustomerMapper;
import com.vehicle.mapper.RentalsMapper;
import com.vehicle.pojo.Cars;
import com.vehicle.pojo.Customers;
import com.vehicle.pojo.DTO.VehicleQueryDTO;
import com.vehicle.pojo.VO.CarVO;
import com.vehicle.pojo.VO.CustomersVO;
import com.vehicle.pojo.VO.VehicleQueryVO;
import com.vehicle.result.PageResult;
import com.vehicle.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private CarMapper carMapper;

    @Autowired
    private RentalsMapper rentalsMapper;
    /**
     * 注册
     * @param customers
     * @return
     */
    @Override
    public Boolean SignIn(Customers customers) {

        Customers customer= customerMapper.GetByName(customers);
        if(customer != null){
            return false;
        }
        customerMapper.SignIn(customers);
        return true;
    }

    @Override
    public Boolean login(Customers customers) {
            Customers customer = customerMapper.selectById(customers);
        System.out.println(customer);
        if(customer != null){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 分页查询
     * @param vehicleQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(VehicleQueryDTO vehicleQueryDTO) {
        log.info("分页查询");
        PageHelper.startPage(vehicleQueryDTO.getPage(), vehicleQueryDTO.getPageSize());
        Page<VehicleQueryVO> carsPage = carMapper.pageQuery(vehicleQueryDTO);
        Long total = carsPage.getTotal();
        List<VehicleQueryVO> recode = carsPage.getResult();
        return new PageResult(total,recode);
    }

    /**
     * 根据Id查询车辆信息
     * @param id
     * @return
     */
    @Override
    public CarVO selectById(Long id) {
        Cars cars= carMapper.selectById(id);
        CarVO carVO = new CarVO();
        BeanUtils.copyProperties(cars,carVO);
/*        String brand = carMapper.selectBrandById(cars.getBrandKey());
        carVO.setBrand(brand);*/
        return carVO;
    }
}
